package com.mooc.yohoshop.ui.gesturelockview;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.mooc.yohoshop.R;
import com.mooc.yohoshop.filed.EventAction;
import com.zyyoona7.lock.GestureLockLayout;

import org.greenrobot.eventbus.EventBus;

public class GesturelockActivity extends AppCompatActivity implements View.OnClickListener{

    private GestureLockLayout mGestureLockLayout;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gesturelock);
        findViewById(R.id.back).setOnClickListener(this);
        mGestureLockLayout= (GestureLockLayout) findViewById(R.id.l_gesture_lock_view);
        mGestureLockLayout.setDotCount(3);
        mGestureLockLayout.setMode(GestureLockLayout.VERIFY_MODE);
        mGestureLockLayout.setTryTimes(100);
        mGestureLockLayout.setAnswer(0,1,2);
        mGestureLockLayout.setOnLockVerifyListener(new GestureLockLayout.OnLockVerifyListener() {
            @Override
            public void onGestureSelected(int id) {

            }

            @Override
            public void onGestureFinished(boolean isMatched) {
                if (isMatched) {
                    Toast.makeText(GesturelockActivity.this,"密码正确",Toast.LENGTH_SHORT).show();
                    EventAction action = new EventAction();
                    action.action = "OK";
                    EventBus.getDefault().post(action);
                    finish();
                }else {
                    Toast.makeText(GesturelockActivity.this,"密码不正确",Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public void onGestureTryTimesBoundary() {

            }
        });
    }

    @Override
    public void onClick(View v) {
        finish();
    }
}
